$(function(){
	checkAds($(window).width());
	$(window).resize(function(){
		checkAds($(window).width());
	});
});
function checkAds(windowWidth){
	ad_width = 120;
	posLeft	= (windowWidth - 992)/2 - ad_width - 3;
	posRight	=	(windowWidth - 1000)/2 - ad_width + 1;
	if(windowWidth < 1000){
		$("#ad_left, #ad_right").hide();
	}else{
		$("#ad_left, #ad_right").show();
		$("#ad_left").css({ top: 5, left: posLeft, position: (/msie|MSIE 6/.test(navigator.userAgent) ? "absolute" : "fixed"), top : 2 });
		$("#ad_right").css({ top: 5, right: posRight, position: (/msie|MSIE 6/.test(navigator.userAgent) == true ? "absolute" : "fixed"), top : 2 });
	}
}


$(function(){
	 // gplus
	 $("#gplus").html('<g:plusone size="small" href="'+WEB_URL+'"></g:plusone>');
	  (function() {
		var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
		po.src = 'https://apis.google.com/js/plusone.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
	  })();  
	
	// category dropdown
	$('#category').dropDownMenu({timer: 300, parentMO: 'parent-hover', childMO: 'child-hover'});
	
	// fill placeholder
	$("input, textarea").each(function(){
		$(this).attr('placeholder', $(this).attr('title'));
	});
	
	// search
	$("#search").submit(function(){
		return false;
	})
	.find(".input").keypress(function(e){
		// enter
		if(e.keyCode == 13 && $.trim($(this).val()) != '') {
			var keyword = $(this).val().replace(new RegExp(/[\s*]/g), '-');
			window.location.href = WEB_URL + 'search/'+keyword+'/';
		}
	});

	// spoiler
	$(".spoiler .spoiler-title").attr('title', 'Click vào đây ẩn/ hiện nội dung').click(function(){
		var parent = $(this).parent();
		var content = $(parent).find('.spoiler-body');
		if($(parent).hasClass('active')) {
			$(content).slideUp(150);
			$(parent).removeClass('active');
		}
		else {
			$(content).slideDown(150);
			$(parent).addClass('active');
			//scrollTop(this);
		}
	});
	
	// resize image
	$("#entry .message img").each(function() {
		if($(this).width() > 600) {
			$(this).css('width', 600);
		}
    });
	// hide preview
	$("#review").hide();
	
	$('a[rel*=facebox]').facebox({
        loadingImage: RESOURCE_URL + 'js/jquery/facebox/loading.gif',
        closeImage: RESOURCE_URL + 'js/jquery/facebox/closelabel.png',
        opacity: 0.3,
    });
	// show request
	//$("#request-button").slideToggle();
	
});